#!/usr/bin/env node

var width = 960,
    height = 500;

var fs = require("fs"),
    topojson = require("topojson"),
    Canvas = require("canvas"),
    d3 = require("d3");

var canvas = new Canvas(width, height),
    context = canvas.getContext("2d");

var us = require("./data/us-10m.json");

var path = d3.geo.path()
    .projection(d3.geo.albers())
    .context(context);

context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);

context.beginPath();
path(topojson.feature(us, us.objects.land));
context.fillStyle = "#000";
context.fill();

context.beginPath();
path(topojson.mesh(us, us.objects.counties, function(a, b) { return a !== b && !(a.id / 1000 ^ b.id / 1000); }));
context.lineWidth = 0.5;
context.strokeStyle = "#fff";
context.stroke();

context.beginPath();
path(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }));
context.lineWidth = 1;
context.strokeStyle = "#fff";
context.stroke();

console.warn("↳ test/images/albers.png");
canvas.pngStream().pipe(fs.createWriteStream("test/images/albers.png"));
